--[[
    @desc 工具类
    @author zch
    @data:2022-04-15 14:00:00
]]

-- 打印调用函数的堆栈
function PrintCallStack()
	local level = 1
	while true do
		local info = debug.getinfo(level, "Sl")
		if not info then break end
		if info.what == "C" then
			print(level, "C function")
		else
			print(string.format("[%s]:%d", info.short_src, info.currentline))
		end
		level = level + 1
	end
end

-- local str = ""
function PrintTable(tbl)
	if tbl == nil or type(tbl) ~= "table" then
		return
	end

	level = level or 1

	local indent_str = ""
	for i = 1, level do
		indent_str = indent_str.."	"
	end
	print(indent_str .. "{")
	-- str = str .. indent_str .. "{"
	for k,v in pairs(tbl) do
		local item_str = string.format("%s%s = %s", indent_str .. "	",tostring(k), tostring(v))
		print(item_str)
		-- str = str .. item_str
		if type(v) == "table" then
			PrintTable(v, level + 1)
		end
	end
	print(indent_str .. "}")
	-- str = str .. indent_str .. "}"
	-- print(str)
end

function IsEmpty(t)
	return not t or _G.next(t) == nil
end

-- 输出非数组类型的数据大小
function TableSize(t)
	if IsEmpty(t) then
		return 0
	end
	local len = 0
	for _, v in pairs(t) do
		len = len + 1
	end
	return len
end

function AddClickEvent(target, call_back)
	if target then
		local function call_back_2(target, ...)
			call_back(target, ...)
		end
		LuaClickListener.Get(target).onClick = call_back_2
	end
end